<%@ page language="java" 
	contentType="text/html; 
	charset=UTF-8"
	pageEncoding="UTF-8"
	import="connectMysql.TestConnect"
	%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<style>
	.center {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        height: 70vh;
    }
    .button {
       margin-right: 10px;
            margin-left: 10px;
            height: 100px;
            width: 200px;
            font-size: 24px;
            font-weight: bold;
            border-radius: 10px;
            background-color: #4CAF50; /* Green */
            color: white;
    }
    .select-box {
        width: 100%;
        height: 40px;
        font-size: 20px;
        display: flex;
        align-items: center;
        text-align: center;
        justify-content: center;
    }
	input[type="submit"],input[type="button"] {
			text-align: center;
			background-color: #4CAF50;
			color: #fff;
			padding: 10px 20px;
			border-radius: 5px;
			border: none;
			cursor: pointer;
		}
		input[type="submit"]:hover ,input[type="button"]:hover{
			background-color: #3e8e41;
		}
		.return_button {
            position: fixed;
            bottom: 20px;
            right: 20px;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            font-size: 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
	</style>
</head>
<body>
	<%
    	String userid=request.getParameter("id");
		String classname=request.getParameter("classname");
		String []homework_data=connectMysql.TestConnect.get_all_homework(classname,userid);
		String []exam_data=connectMysql.TestConnect.get_all_exam(classname,userid);
		String teacher_name=connectMysql.TestConnect.get_class_teacher(classname);
		boolean user_type=connectMysql.TestConnect.judge_user_type(userid);
		//class_data    [name]   [start]   [end]
    %>
    <script >
		var homework = ["作业名称—————————开始时间———————————结束时间———————完成情况"];
		var exam = ["考试名称—————————开始时间———————————结束时间———————提交情况"];
		
	  <% if(homework_data[0]!=null){
		  for (int i = 0; i < homework_data.length; i++) { %>
	    	homework.push("<%= homework_data[i] %>");
	    
	  <% }} %>
	  
	  <% if(exam_data[0]!=null){
		  for (int i = 0; i < exam_data.length; i++) { %>
	    	exam.push("<%= exam_data[i] %>");
	    
	  <% }} %>
	</script>
    <br>
    <div style="position:absolute; top:0; right:0;">
		<input type="button"  onclick="insert_work()" value="发布"/>
	</div>
	<div style="position:absolute; top:0; left:60;font-size: 10px">
		<h1 id="user_id">工号:<%=userid %></h1>
		<h1 id="class_name">课程名称：<%=classname %></h1>
		<h1 id="class_name">授课老师：<%=teacher_name %></h1>
	</div>
	<div class="center">
	    <button class="button" id="homework" onclick="show_select(this.id)">我的作业</button>
	    <button class="button" id="exam" onclick="show_select(this.id)">我的考试</button>
	    <button class="button" id="ppt" onclick="show_select(this.id)">我的课件</button>
	</div>
	<div >
		<select id="mySelect" class="select-box" style="overflow-y: scroll;"></select>
	</div>
	<button class="return_button" onclick="back()">退出</button>
		
	<script>
	function insert_work(){
		window.location="init_homework.jsp?id=<%=userid%>&classname=<%=classname%>";
	}
	
	function back(){
		window.location="login.jsp";
	}
	function show_select(id) {
        var select = document.getElementById("mySelect");
        select.innerHTML = ""; // 清空select之前元素
        
        var options;
        if (id === "exam") {
            options = exam;
        } else if (id === "homework") {
            options = homework;
        } else if (id === "ppt") {
            options = courseware;
        } else {
            options = [];
        }
        
        for (var i = 0; i < options.length; i++) {
            var option = document.createElement("option");
            option.text = options[i];
            select.add(option);
        }
        
        select.addEventListener("change", function() {
            var selectedOption = select.value;
            
            if(<%=user_type%>){
            	if (id === "exam") {
                    // 根据选项跳转到相应的页面
                    for (var i = 0; i < exam.length; i++) {
                        if (selectedOption === exam[i]) {
                            window.location.href = "judge_exam.jsp?class_name=<%=classname%>&userid=<%=userid%>&exam_id="+(i+1);
                            break;
                        }}}
                if (id === "homework") {
                	
                    // 根据选项跳转到相应的页面
                    for (var i = 0; i < homework.length-1; i++) {
                        if (selectedOption === homework[i+1]) {
                            window.location.href = "judge_homework.jsp?class_name=<%=classname%>&user_id=<%=userid%>&work_id="+(i+1);
                            break;
                        }}}
                if (id === "ppt") {
                    // 根据选项跳转到相应的页面
                    for (var i = 0; i < courseware.length; i++) {
                        if (selectedOption === courseware[i]) {
                            window.location.href = "text.html?id=<%=userid%>&ware_name=" + courseware[i];
                            break;
                        }}}
            }else{
            	if (id === "exam") {
                    // 根据选项跳转到相应的页面
                    for (var i = 0; i < exam.length; i++) {
                        if (selectedOption === exam[i]) {
                            window.location.href = "handin_exam.jsp?class_name=<%=classname%>&userid=<%=userid%>&work_id="+(i);
                            break;
                        }}}
                if (id === "homework") {
                	
                    // 根据选项跳转到相应的页面
                    for (var i = 0; i < homework.length-1; i++) {
                        if (selectedOption === homework[i+1]) {
                            window.location.href = "handin_homework.jsp?class_name=<%=classname%>&userid=<%=userid%>&work_id="+(i+1);
                            break;
                        }}}
                if (id === "ppt") {
                    // 根据选项跳转到相应的页面
                    for (var i = 0; i < courseware.length; i++) {
                        if (selectedOption === courseware[i]) {
                            window.location.href = "text.html?id=<%=userid%>&ware_name=" + courseware[i];
                            break;
                        }}}
            }
        });
    }
	
	</script>
</body>
</html>